package com.ganmiao.web.portal.controller.user;

import com.ganmiao.annotation.NoAuthorization;
import com.ganmiao.resp.CommonResultRes;
import com.ganmiao.resp.MobBaseRes;
//import com.ganmiao.server.supplier.dto.SupplierInfoDto;
import com.ganmiao.server.sys.dto.RetrievePasswordDto;
import com.ganmiao.server.sys.entity.SysUserAccount;
import com.ganmiao.server.user.service.UserLoginService;
import com.ganmiao.server.user.vo.SMSCodeVo;
import com.ganmiao.server.user.vo.UserLonginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户登录
 */
@Api(tags = "用户登录")
@Slf4j
@RestController
@RequestMapping("/userLogin")
public class UserLoginController {

    //用户登录
    @Autowired
    private UserLoginService userLoginService;

    /**
     * 用户登录
     *
     * @param sysUserAccount
     * @return
     */
    @NoAuthorization
    @ApiOperation("用户登录")
    @PostMapping("/login")
    public CommonResultRes<UserLonginVo> userLogin(@RequestBody @Validated SysUserAccount sysUserAccount) {
        return new CommonResultRes<>(userLoginService.userLogin(sysUserAccount));
    }

    /**
     * 短信验证码
     *
     * @param mobile
     * @return
     */
    @NoAuthorization
    @ApiOperation("短信验证码")
    @GetMapping("/SMSCode")
    public CommonResultRes<SMSCodeVo> SMSCode(String mobile) {
        return new CommonResultRes<>(userLoginService.SMSCode(mobile));
    }

    /**
     * 验证短信验证码
     *
     * @param mobile,SMScode
     * @return
     */
    @ApiOperation("验证短信验证码")
    @GetMapping("/CheckSMSCode")
    @NoAuthorization
    public CommonResultRes<SMSCodeVo> CheckSMSCode(String mobile,String SMScode) {
        return new CommonResultRes<>(userLoginService.CheckSMSCode(mobile,SMScode));
    }

    @NoAuthorization
    @ApiOperation("总后台找回密码")
    @PutMapping("/retrievePassword")
    public MobBaseRes retrievePassword(@RequestBody RetrievePasswordDto retrievePasswordDto) {
        return userLoginService.retrievePassword(retrievePasswordDto);
    }

}
